package com.front.managementfront.managementlog.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.front.managementfront.managementlog.entity.ManagementLog;
import com.front.managementfront.managementlog.mapper.ManagementLogMapper;
import com.front.managementfront.managementlog.service.IManagementLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-05-12
 */
@Service
@Transactional
public class ManagementLogServiceImpl extends ServiceImpl<ManagementLogMapper, ManagementLog> implements IManagementLogService {


@Autowired
private ManagementLogMapper managementLogMapper;

@Override
public IPage<ManagementLog> selectPage(Page<ManagementLog> page, ManagementLog managementLog){
        QueryWrapper<ManagementLog> query = Wrappers.query();
        QueryWrapper<ManagementLog> entityWrapper = getEntityWrapper(query, managementLog);
        return managementLogMapper.selectPage(page, entityWrapper);
        }




@Override
public List<ManagementLog> selectList(ManagementLog managementLog){
        QueryWrapper<ManagementLog> query = Wrappers.query();
        QueryWrapper<ManagementLog> entityWrapper = getEntityWrapper(query, managementLog);
        return managementLogMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<ManagementLog> getEntityWrapper(QueryWrapper<ManagementLog> entityWrapper,ManagementLog managementLog){
        //条件拼接
             /*   if(StringUtils.isNotBlank(managementLog.getCostTime())){
                entityWrapper.like(ManagementLog.COST_TIME,managementLog.getCostTime());
                }
                if(StringUtils.isNotBlank(managementLog.getCreateTime())){
                entityWrapper.like(ManagementLog.CREATE_TIME,managementLog.getCreateTime());
                }*/
                if(StringUtils.isNotBlank(managementLog.getIp())){
                entityWrapper.like(ManagementLog.IP,managementLog.getIp());
                }
                if(StringUtils.isNotBlank(managementLog.getIpInfo())){
                entityWrapper.like(ManagementLog.IP_INFO,managementLog.getIpInfo());
                }
            /*    if(StringUtils.isNotBlank(managementLog.getLogType())){
                entityWrapper.like(ManagementLog.LOG_TYPE,managementLog.getLogType());
                }*/
                if(StringUtils.isNotBlank(managementLog.getName())){
                entityWrapper.like(ManagementLog.NAME,managementLog.getName());
                }
                if(StringUtils.isNotBlank(managementLog.getRequestParam())){
                entityWrapper.like(ManagementLog.REQUEST_PARAM,managementLog.getRequestParam());
                }
                if(StringUtils.isNotBlank(managementLog.getRequestType())){
                entityWrapper.like(ManagementLog.REQUEST_TYPE,managementLog.getRequestType());
                }
                if(StringUtils.isNotBlank(managementLog.getRequestUrl())){
                entityWrapper.like(ManagementLog.REQUEST_URL,managementLog.getRequestUrl());
                }
                if(StringUtils.isNotBlank(managementLog.getUsername())){
                entityWrapper.like(ManagementLog.USERNAME,managementLog.getUsername());
                }
              /*  if(StringUtils.isNotBlank(managementLog.getCityLat())){
                entityWrapper.like(ManagementLog.CITY_LAT,managementLog.getCityLat());
                }
                if(StringUtils.isNotBlank(managementLog.getCityLon())){
                entityWrapper.like(ManagementLog.CITY_LON,managementLog.getCityLon());
                }*/
                if(StringUtils.isNotBlank(managementLog.getIsLastTimeLogin())){
                entityWrapper.like(ManagementLog.IS_LAST_TIME_LOGIN,managementLog.getIsLastTimeLogin());
                }
                if(StringUtils.isNotBlank(managementLog.getLoginCity())){
                entityWrapper.like(ManagementLog.LOGIN_CITY,managementLog.getLoginCity());
                }
        return entityWrapper;
        }
        }
